
const app = getApp()
import Dialog from '/@vant/weapp/dialog/dialog';
const previewUtil = require("./../../utils/preview.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo: {},
        remarkText: '暂无个性签名哦',
        checked: false,
        readonly: true,
        remarkFocus: false
    },
    /**
     * 将微信小程序的头像显示为高清
     * @param {*} event
     */
    toPreviewWeChatAvatarUrlImage(event) {
        previewUtil.previewWeChatAvatarUrlImage(event);
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getUserInfo();
    },
    onChange({detail}) {
        if (detail === true) {
            this.setData({
                readonly: false,
                remarkText: '',
                remarkFocus: true
            })
        } else {
            this.setData({
                readonly: true,
                remarkText: '暂无个性签名哦'
            })
        }
        this.setData({
            checked: detail
        });
    },
    /**
     * 获取用户信息
     */
    getUserInfo() {
        let that = this;
        wx.request({
            url: app.globalData.baseUrl + '/sys/getUserInfo',
            method: "GET",
            header: {
                "token": wx.getStorageSync('token')
            },
            success: function (res) {
                if (res.data.code === 200) {
                    that.setData({
                        userInfo: res.data.result
                    })
                } else if (res.data.code === 500) {
                    if (wx.getStorageSync('token') === null || wx.getStorageSync('token') === '') {
                        Dialog.alert({
                            title: '温馨提示',
                            message: '尚未授权登录，前往授权页面',
                            theme: 'round-button',
                        }).then(() => {
                            wx.switchTab({
                                url: '../mine/mine'
                            })
                        });
                    }
                }
            }
        })
    },


    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.getUserInfo();
        wx.showToast({
            title: '更新用户信息成功',
            icon: 'none',
            duration: 1500
        });
        wx.stopPullDownRefresh();
    },

    onShow: function () {
        this.getUserInfo();
    },

})
